package com.zofer.study.stack;

import java.util.Arrays;

/**
 * 手写一个栈，含有push,pop,resize方法
 */
public class MyStack<T> {

    private Object[] stack = null;
    private int size = 0;
    public MyStack() {
        this.stack = new Object[10];
    }

    public void push(T t){
        if (size > stack.length) {
            resize();
        }
        stack[size] = t;
        size++;
    }

    public void resize(){
        int resize = stack.length * 3 / 2+1;
        stack = Arrays.copyOf(stack,resize);
    }

    public T pop(){
        T t = null;
        if (size > 0) {
           t = (T)stack[size--];
        }
        return t;
    }

}
